package org.ttjhome.html.struts.util;

import java.util.Hashtable;
import java.util.List;

import org.ttjhome.db.dbo.Tag;
import org.ttjhome.server.HunterServiceFactory;



public final class TagsCache {

	private static Hashtable<String , Tag> tags ;
	
	public static synchronized Tag getTag(String tag){
		if(tags==null)
		{
			tags=new Hashtable<String, Tag>();
			List<Tag> all = HunterServiceFactory.createHunterService().getAllTags();
			for(Tag tagfromDb:all){
				tags.put(tagfromDb.getTag(), tagfromDb);
			}
		}
		return tags.get(tag);
	} 
	
	public static synchronized Tag saveTag(Tag tag)
	{
		Tag oldone = getTag(tag.getTag());
		if(oldone!=null)
			return oldone;
		tags.put(tag.getTag(), tag);
		return tag;
		
	}
	
	
	 
}
